package thread;

/**
 * 守护线程
 */
public class DaemonThread {

    public static void main(String[] args) throws Exception {

        Thread thread = new Thread(
                ()->{
                    while (true) {
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
        );
        // 将Thread设置为守护线程
        thread.setDaemon(true);
        thread.start();
        Thread.sleep(2_000L);
        System.out.println("main thread finished lifecycle.");
    }

}
